import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:get/get.dart';
import 'package:meePet/app/AppPages.dart';
import 'package:meePet/app/RouteConstants.dart';

import 'app/InitSDK.dart';
import 'generated/l10n.dart';

void main() async {
  runApp(const LocalApp());
  if (Platform.isAndroid) {
    // 设置状态栏背景及颜色
    SystemUiOverlayStyle systemUiOverlayStyle =
        const SystemUiOverlayStyle(statusBarColor: Colors.transparent);
    SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
  }
}

class LocalApp extends StatelessWidget {
  const LocalApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    ///全局初始化一些东西
    InitSDK.initThirdPartSDK(context);

    return GetMaterialApp(
      initialRoute: RouteConstants.splashPage,
      getPages: AppPages.pages,
      title: "",
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
      ),
      //设置默认语言
      //locale: const Locale("en"),
      //配置支持的语言
      supportedLocales: const [
        Locale('en', 'US'), //英文
        Locale('zh', 'CN'), //简体中文
      ],
      localizationsDelegates: const [
        S.delegate,
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      localeResolutionCallback: (local, supportedLocals) {
        //根据系统语言设置语言
        if (local?.languageCode == "UK") {
          return const Locale("en");
        } else {
          return const Locale("zh");
        }
      },
      //home: RouteManager.to(RouteConstants.mainPage),
    );
  }
}
